<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8" style="padding: 10px 19px;">
      <el-radio v-model="radio" label="1" @change="getValue()">按警情类型分析</el-radio>
      <el-radio v-model="radio" label="2" @change="getValue()">按报警情况分析</el-radio>
      <el-radio v-model="radio" label="3" @change="getValue()">按严重等级分析</el-radio>
      <el-radio v-model="radio" label="4" @change="getValue()">按人员伤亡及财产损失分析</el-radio>
    </el-row>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="创建开始时间" prop="createTimeBegin" label-width="100px">
        <el-date-picker clearable size="small"
                        v-model="queryParams.createTimeBegin"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择创建开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建结束时间" prop="createTimeEnd" label-width="100px">
        <el-date-picker clearable size="small"
                        v-model="queryParams.createTimeEnd"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择创建结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="evtInfoList" v-show="evtInfoShow">
      <el-table-column label="报警情况" align="center" prop="policeName"/>
      <el-table-column label="接警数量" align="center" prop="policeNum"/>
    </el-table>
    <el-table v-loading="loading" :data="evtLevelList" v-show="evtLevelShow">
      <el-table-column label="案件等级" align="center" prop="policeName"/>
      <el-table-column label="接警数量" align="center" prop="policeNum"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div id="myChart"></div>

  </div>
</template>

<script>
  import {policeInformationStatistics, policeLevelStatistics} from "@/api/frontierEvent/event";
  import echarts from "echarts";

  export default {
    name: "policeInformationStatistics",
    components: {},
    data() {
      return {
        radio: '2',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        evtInfoShow: true,
        evtLevelShow: false,
        echartsTitle: "报警情况分析",
        // 总条数
        total: 0,
        // 船舶信息表格数据
        evtInfoList: [],
        evtLevelList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 案件来源字典
        evtTypeOptions: [],
        dateCycleOptions: [],
        // 管辖区字典
        areaNameOptions: [],
        nameList: [],
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          createTimeBegin: undefined,
          createTimeEnd: undefined,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
      this.getDicts("evt_violation_type").then(response => {
        this.evtTypeOptions = response.data;
      });
      this.getDicts("date_cycle").then(response => {
        this.dateCycleOptions = response.data;
      });
      this.getDicts("evt_area").then(response => {
        this.areaNameOptions = response.data;
      });
    },
    methods: {
      getValue() {
        //console.log(this.radio); // 打印的值，就是被选中的radio的值，1,2
        switch (this.radio) {
          case "1":
            break;
          case "2":
            this.evtInfoShow = true;
            this.evtLevelShow = false;
            break;
          case "3":
            this.msgSuccess('此功能为预留项')
            // this.evtInfoShow = false;
            // this.evtLevelShow = true;
            break;
          case "4":
            break;
        }
        this.getList();
      },
      /** 查询船舶信息列表 */
      getList() {
        this.loading = true;
        switch (this.radio) {
          case "1":
            this.echartsTitle = "警情类型分析";
            this.msgSuccess('此功能为预留项');
            break;
          case "2":
            this.echartsTitle = "报警情况分析";
            policeInformationStatistics(this.queryParams).then(response => {
              this.evtInfoList = response.rows;
              this.loadEcharts(response);
            });
            break;
          case "3":
            this.echartsTitle = "严重等级分析";
            policeLevelStatistics(this.queryParams).then(response => {
              this.evtLevelList = response.rows;
              this.loadEcharts(response);
            });
            break;
          case "4":
            this.echartsTitle = "人员伤亡及财产损失分析";
            this.msgSuccess('此功能为预留项');
            break;
        }
      },
      loadEcharts(response) {
        this.total = response.total;
        this.loading = false;

        this.nameList = [];
        this.dataList = [];
        for (var i = 0; i < response.rows.length; i++) {
          this.nameList.push(response.rows[i].policeName);
          this.dataList.push(response.rows[i].policeNum);
        }


        // 实例化echarts对象
        let myChartDrawer = echarts.init(document.getElementById('myChart'))

        // 绘制条形图
        var option = {
          backgroundColor: '#0C2E59',
          color: ['#91c7ae'],
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'line'
            }
          },
          title: {
            text: this.echartsTitle,
            top: 5,
            left: 'center',
            textStyle: {
              color: '#F5F6F8'
            }
          },
          legend: {
            data: ['接警数量'],
            top: 30,
            textStyle: {
              color: '#F5F6F8'
            }
          },
          // X轴
          xAxis: {
            data: this.nameList,
            axisLabel: {
              interval: 0,
              rotate: 40
            },
            axisLine: {
              lineStyle: {
                color: '#F5F6F8'
              }
            }
          },
          // Y轴
          yAxis: {
            axisLine: {
              lineStyle: {
                color: '#F5F6F8'
              }
            }},
          // 数据
          series: [
            {
              name: '接警数量',
              type: 'bar',
              data: this.dataList,
              barWidth: 30,
              itemStyle: {
                normal: {
                  color: '#5AC4B9'
                }
              }
            }
          ]
        };

        myChartDrawer.setOption(option);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      }
    }
  };
</script>

<style>
  #myChart {
    width: 70%;
    min-height: 400px;
    clear: both;
    box-sizing: border-box;
    margin: 80px auto;
  }
</style>
